/*
 * SimSetupPanel.java
 *
 * Created on April 9, 2008, 12:47 PM
 */

package protovitae.ui;

import javax.swing.JOptionPane;

/**
 *
 * @author  krattp
 */
public class SimSetupPanel extends javax.swing.JPanel {
    
    /** Creates new form SimSetupPanel */
    public SimSetupPanel() {
        initComponents();
    }
    
    /** Get the value entered as a health modification in this panel. Values outside -199 to 199 are invalid **/
    public int getHealthMod(){
        int retval = 250;
        
        try{
            retval = Integer.parseInt(txtHealthMod.getText());
            if(retval <= -200 || retval >= 200){
                JOptionPane.showMessageDialog(this, "You have created a dangerous situation. Health modifications should be less than 200.");
                retval = 250;
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "The change in health should be a whole number.");
            retval = 250;
        }
        
        return retval;
    }
    
    /** Get the value entered for cycles in this panel, value is -1 if not valid. **/
    public int getCycles(){
        int retval = -1;
        
        try{
            retval = Integer.parseInt(txtCycles.getText());
            if(retval <= 0){
                JOptionPane.showMessageDialog(this, "The mumber of cycles must be more than zero.");
                retval = -1;
            }
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "The number of cycles must be a whole number.");
            retval = -1;
        }
        
        return retval;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblSimProps = new javax.swing.JLabel();
        txtCycles = new javax.swing.JTextField();
        lblCycles = new javax.swing.JLabel();
        pnlHelp = new javax.swing.JPanel();
        scrHelp = new javax.swing.JScrollPane();
        txtHelp = new javax.swing.JTextArea();
        txtHealthMod = new javax.swing.JTextField();
        lblHealthMod = new javax.swing.JLabel();

        lblSimProps.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblSimProps.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblSimProps.setText("Set up your simulation properties:");

        txtCycles.setText("10000");

        lblCycles.setText("Number of cycles:");

        pnlHelp.setBorder(javax.swing.BorderFactory.createTitledBorder("Quick help:"));

        scrHelp.setBorder(null);
        scrHelp.setEnabled(false);

        txtHelp.setColumns(20);
        txtHelp.setEditable(false);
        txtHelp.setLineWrap(true);
        txtHelp.setRows(5);
        txtHelp.setText("The number of cycles represents how many unique \"steps\" that the simulation will run for. During each cycle, every organism will have the opportunity to perform one action (move, eat, etc.) from one of its genes. The health loss per cycle represents how many health points (Maximum: 200) an organism will lose during each \"step\" of the simulation. You can change this value to simulate different enviironment conditions.\nNote: All of the settings above should be whole numbers.");
        txtHelp.setWrapStyleWord(true);
        scrHelp.setViewportView(txtHelp);

        javax.swing.GroupLayout pnlHelpLayout = new javax.swing.GroupLayout(pnlHelp);
        pnlHelp.setLayout(pnlHelpLayout);
        pnlHelpLayout.setHorizontalGroup(
            pnlHelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlHelpLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrHelp, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlHelpLayout.setVerticalGroup(
            pnlHelpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlHelpLayout.createSequentialGroup()
                .addComponent(scrHelp, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                .addContainerGap())
        );

        txtHealthMod.setText("0");

        lblHealthMod.setText("Health loss per cycle:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pnlHelp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblCycles)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCycles, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE))
                    .addComponent(lblSimProps, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(lblHealthMod)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtHealthMod, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblSimProps)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCycles)
                    .addComponent(txtCycles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblHealthMod)
                    .addComponent(txtHealthMod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(pnlHelp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblCycles;
    private javax.swing.JLabel lblHealthMod;
    private javax.swing.JLabel lblSimProps;
    private javax.swing.JPanel pnlHelp;
    private javax.swing.JScrollPane scrHelp;
    private javax.swing.JTextField txtCycles;
    private javax.swing.JTextField txtHealthMod;
    private javax.swing.JTextArea txtHelp;
    // End of variables declaration//GEN-END:variables
    
}
